package com.github.jaskey.rocketmq;

import org.springframework.data.redis.connection.RedisClusterConfiguration;
import org.springframework.data.redis.connection.RedisNode;
import org.springframework.data.redis.connection.RedisPassword;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import java.util.Collections;
import java.util.List;
import java.util.Objects;
public class RedisTest {
    public static void main(String[] args) {
        //单机模式
        RedisStandaloneConfiguration rsc = new RedisStandaloneConfiguration();
        rsc.setPort(8635);
        rsc.setPassword(RedisPassword.of("Bmf6shzb7b!"));
        rsc.setHostName("124.71.157.219");



        StringRedisTemplate template = new StringRedisTemplate();
        //单机模式
        JedisConnectionFactory fac = new JedisConnectionFactory(rsc);
        //集群模式
        //JedisConnectionFactory fac = new JedisConnectionFactory(rcc);
        fac.afterPropertiesSet();
        template.setDefaultSerializer(new StringRedisSerializer());
        template.setConnectionFactory(fac);
        template.afterPropertiesSet();
        ValueOperations<String, String> op = template.opsForValue();

        final String key = "123_tmp";
        final String value = "abc";
        template.delete(key);
        op.set(key, value);
        assert Objects.equals(op.get(key), value);
    }
}
